package top.oneit.jdownload.test;

import com.jfoenix.animation.alert.JFXAlertAnimation;
import com.jfoenix.controls.JFXAlert;
import com.jfoenix.controls.JFXButton;
import com.jfoenix.controls.JFXDialogLayout;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.stage.Modality;
import javafx.stage.Stage;

/**
 * @author lingkang
 * @date 2021/11/14
 */
public class AlertDemo extends Application {
    private JFXAlert<Void> alert;

    @Override
    public void start(Stage stage) throws Exception {
        JFXButton leftButton = new JFXButton("Alert");
        leftButton.setLayoutX(50);
        leftButton.setLayoutY(50);
        Group group = new Group(leftButton);
        stage.setWidth(600);
        stage.setHeight(300);
        stage.setScene(new Scene(group));

        JFXButton jfxButton = new JFXButton("覆盖文件");
        jfxButton.setButtonType(JFXButton.ButtonType.RAISED);
        jfxButton.setStyle("-fx-background-color: #409eff");
        jfxButton.setOnAction(act -> {
            alert.hide();
        });

        JFXButton cancel = new JFXButton("取消");
        cancel.setStyle("-fx-background-color: #d3d4d6");
        cancel.setOnAction(act -> {
            alert.hide();
        });

        JFXDialogLayout layout = new JFXDialogLayout();
        layout.setBody(new Label("下载文件已经存在，是否覆盖原文件？"));
        layout.setActions(jfxButton, cancel);

        alert = new JFXAlert<>(stage);
        alert.setOverlayClose(true);
        alert.setAnimation(JFXAlertAnimation.CENTER_ANIMATION);
        alert.setContent(layout);
        alert.initModality(Modality.NONE);
        leftButton.setOnAction(action -> alert.showAndWait());

        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
